<?php

function print_tree( $fl ){
	
	if (is_array($fl) && count($fl) > 0){
		print '<ul>';
		// Directories
		foreach( $fl['d'] as $d=>$v ){
			print '<li class="closed"><label class="directory" rel="'.$v['inode'].'">&nbsp;</label><a href="">'.$d.'</a>';
			print_tree(&$v['content']);
			print '</li>';
		}
	
		// Files
		foreach( $fl['f'] as $file=>$inode ){
			print '<li><label class="file ext_'.preg_replace('/^.*\./', '', $file).'" rel="'.$inode.'">&nbsp;</label><a href="">'.$file.'</a>';
			print '</li>';
		}
			
		print '</ul>';
	}
	
}

require_once(LIB_PATH.'/libRVT.php');

$rvt = new RVT();

if ( isset($_POST['items']) ){
	$items = $rvt->arrayExplode(explode('+',$_POST['items']));

	foreach ($items[$_SESSION['case']] as $dev=>$disks){ 
		print '<li class="closed"><label class="device">&nbsp;</label><a href="">'.$dev.'</a><ul>';
		foreach ($disks as $disk=>$parts){
			print '<li class="closed"><label class="disk">&nbsp;</label><a href="">'.$disk.'</a><ul>';
			foreach ($parts as $part=>$p){
				print '<li class="closed"><label class="partition">&nbsp;</label><a href="">'.$part.'</a><ul>';
				$fl = $rvt->getFileList($part);
				if (! empty($fl)){
					print '<li class="closed"><label class="allocated">&nbsp;</label><a href="">Allocated</a>';
					print_tree(&$fl['Allocated']);
					print '</li>';
					print '<li class="closed"><label class="unallocated">&nbsp;</label><a href="">Deleted</a>';
					print_tree(&$fl['Deleted']);
					print '</li>';
				} else {
					print '<li><label class="warning">&nbsp;</label>No se ha extraido el listado de ficheros</li>';
				}
				print '</ul>';
			}
			print '</ul></li>';
		}
		print '</ul></li>';
	}
}

?>
